﻿using EBA.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;

namespace EBA.Tests.Framework
{
    [TestClass]
    public class BundleAnalyzerTest
    {
        [TestMethod]
        public void test_try_load_bundle_manifests()
        {

            var analyzer = new BundleAnalyzer();

            var query = analyzer.GetBundleManifests<IBundle>(AppRuntime.ApplicationPath);
            var bundleId = "BundleAnalyzerTest_Test_TryLoadBundleManifests_Bundle";
            var manifest = query.Where(i => i.Bundle.Id == bundleId).Single();

            Assert.AreEqual(manifest.Bundle.Id, bundleId);

            Assert.IsTrue(manifest.Files.Any(i => i.EndsWith("EBA.Tests.dll")));
        }

     

        #region Test_TryLoadBundleManifests
        [Export("BundleAnalyzerTest_Test_TryLoadBundleManifests_Bundle", typeof(IBundle))]
        public class BundleAnalyzerTest_Test_TryLoadBundleManifests_Bundle : IBundle
        {
            public IBundleContext BundleContext
            {
                get
                {
                    throw new NotImplementedException();
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            public void Start()
            {
                throw new NotImplementedException();
            }

            public void Stop()
            {
                throw new NotImplementedException();
            }

         
            public string Id
            {
                get { return "BundleAnalyzerTest_Test_TryLoadBundleManifests_Bundle"; }
            }

            public string Name
            {
                get { throw new NotImplementedException(); }
            }

            public string Description
            {
                get { throw new NotImplementedException(); }
            }

            public Version Version
            {
                get { throw new NotImplementedException(); }
            }


            public BundleState State
            {
                get { throw new NotImplementedException(); }
            }


            public string StartupPath
            {
                set { throw new NotImplementedException(); }
            }
        }
        #endregion

        [TestMethod]
        public void test_try_load_custom_bundle_manifests()
        {
            var analyzer = new BundleAnalyzer();

            var query = analyzer.GetBundleManifests<bundleanalyzertest_icustombundle>(AppRuntime.ApplicationPath);
            var bundleId = "bundleanalyzertest_custombudle";
            var manifest = query.Where(i => i.Bundle.Id == bundleId).Single();

            Assert.AreEqual(manifest.Bundle.Id, bundleId);
        }

        [TestMethod]
        public void test_try_load_custom_bundle()
        {
            var analyzer = new BundleAnalyzer();

            var query = analyzer.GetBundleManifests<bundleanalyzertest_icustombundle>(AppRuntime.ApplicationPath);
            var bundleId = "bundleanalyzertest_custombudle";
            var manifest = query.Where(i => i.Bundle.Id == bundleId).Single();

            Assert.IsTrue(manifest.Bundle is bundleanalyzertest_icustombundle);
        }

        #region test_try_load_custom_bundle_manifests
        public interface bundleanalyzertest_icustombundle : IBundle
        {

        }

        [Export("bundleanalyzertest_custombudle", typeof(bundleanalyzertest_icustombundle))]
        public class bundleanalyzertest_custombudle : bundleanalyzertest_icustombundle
        {

            public IBundleContext BundleContext
            {
                get;
                set;
            }

            public string Id
            {
                get { return "bundleanalyzertest_custombudle"; }
            }

            public string Name
            {
                get { throw new NotImplementedException(); }
            }

            public string Description
            {
                get { throw new NotImplementedException(); }
            }

            public Version Version
            {
                get { throw new NotImplementedException(); }
            }


            public void Start()
            {
                throw new NotImplementedException();
            }

            public void Stop()
            {
                throw new NotImplementedException();
            }


            public BundleState State
            {
                get { throw new NotImplementedException(); }
            }


            public string StartupPath
            {
                set { throw new NotImplementedException(); }
            }
        } 
        #endregion
    }

   
}

